import multiprocessing
import os

class MyProcess(multiprocessing.Process):
    def __init__(self,name,url,*args,**kwargs):
        super(MyProcess, self).__init__(*args,**kwargs)
        self.name = name
        self.url = url
    def run(self):
        pname = self.name
        pid = os.getpid() #获取pid
        ppid = os.getppid() #获取主进程id
        print("子进程名称:",pname)
        print("子进程id:",pid)
        print("父进程id:",ppid)


if __name__ == '__main__':
    p1 = MyProcess("91","http://www.91.com")
    p2 = MyProcess("free","http://www.free.com")

    p1.start()
    p2.start()

    #cpu的核数
    print(multiprocessing.cpu_count())
    #正在活动的子进程
    print(multiprocessing.active_children())

